/*
 * 2007/05
 * 2007/10
 * 2011/11/17 - 13:54
 */
package org.nettyflux.example.asteroids;

import java.awt.image.BufferedImage;
import java.io.IOException;
import javax.imageio.ImageIO;

/**
 * @author Victor Williams Stafusa da Silva
 */
public class MaskedImage {
    private MaskedImage() {}

    public static BufferedImage load(String s, int maskColor) throws IOException {
        BufferedImage temp = ImageIO.read(MaskedImage.class.getResourceAsStream(s));
        BufferedImage image = new BufferedImage(temp.getWidth(), temp.getHeight(), BufferedImage.TYPE_INT_ARGB);
        for (int x = 0; x < temp.getWidth(); x++) {
            for (int y = 0; y < temp.getHeight(); y++) {
                int pixel = temp.getRGB(x, y);
                if ((pixel & 0x00ffffff) == maskColor) pixel = 0x00ffffff;
                image.setRGB(x, y, pixel);
            }
        }
        return image;
    }
}